﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class public_page_user_trans_query : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {      
            this.txt_date_start.Attributes.Add("onclick", "return Calendar(this.id);");
            this.txt_date_end.Attributes.Add("onclick", "return Calendar(this.id);");


            this.ddl_status.Items.Add(new ListItem("全部", "0"));
            this.ddl_status.Items.Add(new ListItem("成功", "1"));
            this.ddl_status.Items.Add(new ListItem("失败", "2"));


            DataTable dt = DataBaseOperate_SQLServer.GetDataTable("select cost_id,cost_name from t_cost where cost_type=0 order by cost_id");

            ddl_cost_id.DataSource = dt;
            ddl_cost_id.DataValueField = "cost_id";
            ddl_cost_id.DataTextField = "cost_name";
            ddl_cost_id.DataBind();
            ddl_cost_id.Attributes.Add("onchange", "getorg_id(this);");

            ddl_cost_id.Items.Insert(0, new ListItem("全部", "0"));

            DataTable dt2  = DataBaseOperate_SQLServer.GetDataTable("select t1.cost_id,t2.cost_organization_id,t2.cost_organization_name from t_cost t1,t_cost_organization t2 where t1.cost_id=t2.cost_id and t1.cost_type=0 order by t1.cost_id");

            System.Text.StringBuilder sbstr = new System.Text.StringBuilder(300);

            System.Text.StringBuilder sbstr2 = new System.Text.StringBuilder(300);

            sbstr.Append("<script language='JavaScript'>");
  
            sbstr.Append("var arr2cost_org_id=new Array(");

            sbstr2.Append("var arr2cost_org_name=new Array(");


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sbstr.Append("[");
                sbstr.Append(dt.Rows[i][0]);
                sbstr.Append(",");

                sbstr2.Append("[");
                sbstr2.Append("'");
                sbstr2.Append(dt.Rows[i][1]);
                sbstr2.Append("'");
                sbstr2.Append(",");

                for (int j = 0; j < dt2.Rows.Count; j++)
                {
                    if (Convert.ToInt32(dt2.Rows[j][0]) == Convert.ToInt32(dt.Rows[i][0]))
                    {
                        sbstr.Append(dt2.Rows[j][1]);
                        sbstr2.Append("'");
                        sbstr2.Append(dt2.Rows[j][2]);
                        sbstr2.Append("'");

                        sbstr.Append(",");
                        sbstr2.Append(",");
                    }
                }

                sbstr.Remove(sbstr.Length - 1, 1);
                sbstr2.Remove(sbstr2.Length - 1, 1);

                if (i < dt.Rows.Count - 1)
                {
                    sbstr.Append("],");
                    sbstr2.Append("],");
                }
                else
                {
                    sbstr.Append("]");
                    sbstr2.Append("]");
                }

            }

            sbstr.Append(");");
            sbstr2.Append(");");

            sbstr.Append(sbstr2.ToString());
            sbstr.Append("getorg_id(document.getElementById(obj_id_front + 'ddl_cost_id'));");
            sbstr.Append("</script>");

            Formspan.InnerHtml = sbstr.ToString();



            dt = DataBaseOperate_SQLServer.GetDataTable("select t2.cost_organization_id,t2.cost_organization_name from t_cost t1,t_cost_organization t2 where t1.cost_id=t2.cost_id and t1.cost_type=1");

            ddl_cost_recharge_id.DataSource = dt;
            ddl_cost_recharge_id.DataValueField = "cost_organization_id";
            ddl_cost_recharge_id.DataTextField = "cost_organization_name";
            ddl_cost_recharge_id.DataBind();

            ddl_cost_recharge_id.Items.Insert(0, new ListItem("全部", "0"));


        }
        

    }
    protected void btn_query_Click(object sender, EventArgs e)
    {
       // Response.Redirect("user_trans_result.aspx");
       Server.Transfer("user_trans_result.aspx");
    }

    protected void btn_clear_Click(object sender, EventArgs e)
    {
        this.ddl_cost_id.SelectedIndex = 0;
        this.ddl_cost_organization_id.SelectedIndex = 0;
        this.ddl_status.SelectedIndex = 0;

    }
}
